How can I call `update_attribute` for a list item in rails then actually update the html using jquery?
Posted
by
Patrick Connor
on Stack Overflow
See other posts from Stack Overflow
or by Patrick Connor
Published on 2011-02-09T23:24:03Z
Indexed on
2011/02/09
23:25 UTC
Read the original article
Hit count: 233
I want my users to be able to mark one or more items from an index view as "Active" or "Inactive" using a link. The text for the link should be state aware - so it might default to "Mark as Active" if the corresponding attribute was false or null, and "Mark as Inactive" if true. Once the user clicks the link and the attribute is updated in the controller, the link-text should update based on the new state.
I am WAY off here, but this is a small sample of the code I have been trying...
CONTROLLER
...
respond_to :html, :js
...
def update
@item = Item.find(params[:id])
if @item.update_attributes(params[:item])
#Not sure of how to respond to .js here
end
end
...
update.js.erb
#how do I identify which element to update?
$('#item[13456]').html("State aware text for link_to")
VIEW
- for item in @items
= item.name
= link_to "Mark as Active", item_path(item), :method => :put, :remote => true. :id => "item[#{item.id}]"
I am happy to read any APIs, blogs, tutorials, etc. I just can't seem to get my hands/mind around this task. Any help or guidance is greatly appreciated!
© Stack Overflow or respective owner